package com.chtw.vuedemo.service.impl;

import com.chtw.vuedemo.bean.Photos;
import com.chtw.vuedemo.service.inf.PhotoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author chtw
 * @date 2020-10-05 10:03
 */
@Service
public class PhotoServiceImpl {
    @Autowired
    private PhotoService photoService;

    @Autowired
    private MongoTemplate mongo;


    public List<Photos> getPhotoListByCategoryId(int id){
        if (id == 0){
            return photoService.findAll();
        }
        Criteria criteria = new Criteria();
        criteria.and("category_id").is(id);
        Query query = new Query(criteria);
        return mongo.find(query, Photos.class);
    }
}
